#include "createscenariodialog.h"
#include "ui_createscenariodialog.h"

CreateScenarioDialog::CreateScenarioDialog(QWidget *parent)
    : QDialog(parent),
      ui(new Ui::CreateScenarioDialog)
{
    ui->setupUi(this);

    setModal(true);
    installUi();

    _designer = static_cast<ChipsInfo::Designer>(ui->designerComboBox->currentIndex());

    connect(ui->scenarioEdit, SIGNAL(textChanged(QString)), this, SLOT(okEnableReconcile()));
    connect(ui->scenarioEdit, SIGNAL(textChanged(QString)), this, SLOT(setScenarioName(QString)));
    connect(ui->designerComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(setDesigner(int)));
}

CreateScenarioDialog::~CreateScenarioDialog()
{
    delete ui;
}

void CreateScenarioDialog::installUi() const
{
    setIcons();
    ui->okButton->setEnabled(false);
}

void CreateScenarioDialog::setIcons() const
{
    for (int i = 0; i < ui->designerComboBox->count(); ++i)
        ui->designerComboBox->setItemIcon(i, QIcon(":/images/greenpak3.ico"));
}

void CreateScenarioDialog::on_okButton_clicked()
{
    emit scenarioCreated(_scenarioName, _designer);

    close();
}

void CreateScenarioDialog::on_cancelButton_clicked()
{
    close();
}

void CreateScenarioDialog::okEnableReconcile() const
{
    ui->okButton->setEnabled(!ui->scenarioEdit->text().isEmpty());
}

void CreateScenarioDialog::setDesigner(int index)
{
    _designer = static_cast<ChipsInfo::Designer>(index);
}

void CreateScenarioDialog::setScenarioName(const QString &scenarioName)
{
    _scenarioName = scenarioName;
}
